package com.neiru.divider.facade;

import java.util.ArrayList;

import android.content.Context;

import com.neiru.divider.bean.Level;
import com.neiru.divider.dao.LevelDao;

public class LevelFacade {
	private LevelDao levelDao;
	public LevelFacade(Context context) {
		this.levelDao = new LevelDao(context);
	}
	public void createLevel(Level level) {
		this.levelDao.open();
		this.levelDao.createLevel(level);
		this.levelDao.close();
	}
	public void updateLevel(Level level) {
		this.levelDao.open();
		this.levelDao.updateLevel(level);
		this.levelDao.close();
	}
	public Level getLevel(Integer level) {
		this.levelDao.open();
		Level levelObject = this.levelDao.getLevel(level);
		this.levelDao.close();
		return levelObject;
	}
	public Integer getLastLevel() {
		this.levelDao.open();
		Integer lastLevel = this.levelDao.getLastLevel();
		this.levelDao.close();
		return lastLevel;
	}
	public void initializeLevels() {
		this.levelDao.open();
		if(!this.levelDao.existsSomeLevels()) {
			Level level0 = new Level(1, new ArrayList<Integer>(), 3, 3, 3, false);
			Level level1 = new Level(2, new ArrayList<Integer>(), 3, 4, 3, false);
			Level level2 = new Level(3, new ArrayList<Integer>(), 3, 5, 3, false);
			
			Level level3 = new Level(4, new ArrayList<Integer>(), 4, 3, 3, false);
			Level level4 = new Level(5, new ArrayList<Integer>(), 4, 4, 3, false);
			Level level5 = new Level(6, new ArrayList<Integer>(), 4, 5, 3, false);
			Level level6 = new Level(7, new ArrayList<Integer>(), 4, 6, 3, false);
			
			Level level7 = new Level(8, new ArrayList<Integer>(), 5, 4, 3, false);
			Level level8 = new Level(9, new ArrayList<Integer>(), 5, 5, 3, false);
			Level level9 = new Level(10, new ArrayList<Integer>(), 5, 6, 3, false);
			Level level10 = new Level(11, new ArrayList<Integer>(), 5, 7, 3, false);
			Level level11 = new Level(12, new ArrayList<Integer>(), 5, 8, 3, false);

			Level level12 = new Level(13, new ArrayList<Integer>(), 6, 5, 3, false);
			Level level13 = new Level(14, new ArrayList<Integer>(), 6, 6, 3, false);
			Level level14 = new Level(15, new ArrayList<Integer>(), 6, 7, 3, false);
			Level level15 = new Level(16, new ArrayList<Integer>(), 6, 8, 3, false);
			
			Level level16 = new Level(17, new ArrayList<Integer>(), 7, 5, 3, false);
			Level level17 = new Level(18, new ArrayList<Integer>(), 7, 7, 3, false);
			Level level18 = new Level(19, new ArrayList<Integer>(), 7, 8, 3, false);
			Level level19 = new Level(20, new ArrayList<Integer>(), 7, 10, 3, false);
			
			
			levelDao.createLevel(level0);
			levelDao.createLevel(level1);
			levelDao.createLevel(level2);
			levelDao.createLevel(level3);
			levelDao.createLevel(level4);
			levelDao.createLevel(level5);
			levelDao.createLevel(level6);
			levelDao.createLevel(level7);
			levelDao.createLevel(level8);
			levelDao.createLevel(level9);
			levelDao.createLevel(level10);
			levelDao.createLevel(level11);
			levelDao.createLevel(level12);
			levelDao.createLevel(level13);
			levelDao.createLevel(level14);
			levelDao.createLevel(level15);
			levelDao.createLevel(level16);
			levelDao.createLevel(level17);
			levelDao.createLevel(level18);
			levelDao.createLevel(level19);
		}
		this.levelDao.close();
	}
}
